//
//  EmptyView.swift
//  SwiftScienceChina
//
//  Created by 贾培军 on 2019/12/10.
//  Copyright © 2019 贾培军. All rights reserved.
//

import UIKit
import SnapKit
public typealias RetryBlock = ()-> Void
open class SWEmptyView: UIView {
    var contentView = UIView()
    var iconView = UIImageView()
    var retryLabel = UILabel()
    var title: String?{
        set{
            self.retryLabel.text = newValue
        }
        get{
            return self.retryLabel.text
        }
    }
    var retryBlock: RetryBlock?
    var attributedTitle: NSAttributedString?{
        set{
            self.retryLabel.attributedText = newValue
        }
        get{
            return self.retryLabel.attributedText
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        setupLayout()
    }
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    @objc func retry(){
        retryBlock?()
    }
    func setupUI(){
        self.backgroundColor = .white
        contentView.backgroundColor = .white
        
//        iconView.image  = .init(imageLiteralResourceName: "哭脸")
        
        retryLabel.font = UIFont.systemFont(ofSize: 14)
        retryLabel.textColor = .init(999999)
        retryLabel.text = "内容为空,点击试试"
        
        let tap = UITapGestureRecognizer(target: self, action:#selector(self.retry))
        self.addGestureRecognizer(tap)
    }
    func setupLayout(){
        self.addSubview(contentView)
        contentView.snp.makeConstraints { (m) in
            m.top.left.equalTo(10)
            m.bottom.right.equalTo(-10)
        }
        
        contentView.addSubview(iconView)
        iconView.snp.makeConstraints { (m) in
            m.centerX.equalTo(self)
            m.centerY.equalTo(self).offset(-55)
            m.width.height.equalTo(75)
        }
        
        contentView.addSubview(retryLabel)
        retryLabel.snp.makeConstraints { (m) in
            m.centerX.equalTo(self)
            m.top.equalTo(iconView.snp.bottom).offset(10)
        }
    }
    
}
